package com.hyh.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alibaba.fastjson.JSON;
import com.hyh.bean.AdminInfoBean;
import com.hyh.myutils.MyUtils;
import com.hyh.service.impl.AjaxDemoServiceimlp;

/**
 * Ajax查询后台业务逻辑处理
 */
@WebServlet("/AjaxQueryDemoAction")
public class AjaxQueryDemoAction extends HttpServlet {
	private static final long serialVersionUID = 1L;

	
	
	
	@Override
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		//获取表单数据
		AdminInfoBean adminB = MyUtils.convertFormData2Bean(request, AdminInfoBean.class);	
		// 进行查询操作
		List<AdminInfoBean> lstAdmins = MyUtils.getInstance(AjaxDemoServiceimlp.class).queryLoginInfoByParams(adminB);		
		System.out.println("查询结果:"+lstAdmins);
		//借助第三方的工具将集合转换为json字符串【借用阿里巴巴的插件】
		//响应客户端的请求
         String strJson = JSON.toJSONStringWithDateFormat(lstAdmins, "yyyy-MM-dd HH:mm:ss");
	   //将json字符串发回客户端浏览器
		
				PrintWriter pw=	response.getWriter();
			    pw.write(strJson);
			    pw.flush();	
	}

	

}
